"""
Project Euler Problem 7: https://projecteuler.net/problem=7

10001st prime

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we
can see that the 6th prime is 13.

What is the 10001st prime number?
"""

# _*_ conding:UTF-8 _*_
'''
@author = Kuperain
@email = kuperain@aliyun.com
@IDE = Thonny Python3.8
@creat_time = 2022/5/5
'''

import math

def isPrime(n: int) -> bool:
    '''
    >>> isPrime(1)
    False
    >>> isPrime(2)
    True
    >>> isPrime(99*99)
    False
    >>> isPrime(101)
    True
    '''
    if n <= 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    
    n_sqrt = int(math.sqrt(n))
    
    for i in range(3, n_sqrt + 1, 2):
        if  n % i == 0:
            # print(i)
            return False
    return True
    

def solution1(n: int = 10001) -> int:
    '''
    >>> solution1(1)
    2
    >>> solution1(3)
    5
    >>> solution1(6)
    13
    '''
    
    if n == 1:
        return 2

    counter = 1
    i = 3
    while True:
        if isPrime(i):
            #print(i)
            counter += 1
            if counter == n:
                return i
        i += 2
                  

if __name__ == "__main__":
    import doctest

    doctest.testmod(verbose = False)
    
    print(f"{solution1() = }")

    


